package com.lap.auth.application.role.assembler;

import java.util.List;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import com.lap.auth.application.role.command.CreateDataScopeCmd;
import com.lap.auth.application.role.command.CreateRoleCmd;
import com.lap.auth.application.role.dto.RoleDataScopeDto;
import com.lap.auth.domain.role.Role;
import com.lap.auth.domain.role.valueobject.DataScopeType;
import com.lap.auth.domain.role.valueobject.RoleDataScope;
import com.lap.framework.tools.EnumUtil;

@Mapper(componentModel = "spring")
public interface RoleAssembler {

  @Mapping(target = "id", ignore = true)
  Role toDomain(CreateRoleCmd cmd);

  @Mapping(target = "id", ignore = true)
  @Mapping(target = "roleId", source = "roleId")
  @Mapping(target = "scopeType", source = "cmd.dataScopeType")
  RoleDataScope toDomain(Integer roleId, CreateDataScopeCmd cmd);

  @Mapping(target = "dataScopeType",source = "scopeType")
  RoleDataScopeDto toDto(RoleDataScope roleDataScope);

  List<RoleDataScopeDto> toDtoList(List<RoleDataScope> roleDataScope);

  default Integer dataScopeTypeToCode(DataScopeType type) {
    return type.getCode();
  }

  default DataScopeType codeToDataScopeType(Integer code) {
    return EnumUtil.fromCode(DataScopeType.class, code);
  }
}
